package com.google.code;

/**
 * Utility class to help Bunit classes. It is used to hold reusable methods or methods that are out of concrete classes
 * subject.
 * 
 * @author Leopoldo Muller
 */
public class BunitUtils {

    /**
     * Private constructor to avoid instantiation.
     */
    private BunitUtils() {
    }

    /**
     * Check if <code>class2</code> is on of super-classes of <code>class1</code>.
     * 
     * @param class1
     *            the class to iterate over super-classes
     * 
     * @param class2
     *            the class to check if is a super-class of <code>class1</code>
     * 
     * @return <code>true</code> if <code>class2</code> is in hierarchy of <code>class1</code>
     */
    public static boolean isChildOf(Class<?> class1, Class<?> class2) {

        Class<?> superclass = class1.getSuperclass();

        boolean isChildOf = false;

        while (superclass != null) {

            if (superclass.equals(class2)) {

                isChildOf = true;

                break;
            }

            superclass = superclass.getSuperclass();
        }

        return isChildOf;
    }
}
